home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C06 QuickDraw GX / P04 QD GX Shapes / QDGXShape.c next >
Encoding:
C/C++ Source or Header  |  1995-09-01  |  3.9 KB  |  168 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    QDGXShape.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include "PrintingManager.h"      // defines the Gestalt selector code gestaltGXPrintingMgrVersion
  13. #include "graphics macintosh.h"   // defines the Gestalt selector code gestaltGraphicsVersion
  14. #include "graphics toolbox.h"     // prototype for the GX function GXNewWindowViewPort()
  15. #include "graphics libraries.h"   // prototypes for several GX functions
  16.  
  17.  
  18. //____________________________________________________________
  19.  
  20. Boolean  IsQuickDrawGXAvailable( void );
  21. void     InitializeToolbox( void );
  22. void     InitializeQuickDrawGX( void );
  23. void     OpenDisplayWindow( void );
  24. void     CleanUpQuickDrawGXandQuit( void );
  25. void     CreateGXLineShape( void );
  26.  
  27.  
  28. //____________________________________________________________
  29.  
  30. #define     kGXClientHeapSizeBytes    150 * 1024
  31.  
  32.  
  33. //____________________________________________________________
  34.  
  35. gxGraphicsClient  gGXClient;
  36. Boolean           gQuickDrawGXPresent;
  37. WindowPtr         gDisplayWindow = nil;
  38. gxViewPort        gWindowViewPort;
  39. Boolean           gDone = false;
  40. gxShape           gLineShape;
  41.  
  42.  
  43. //____________________________________________________________
  44.  
  45. void  main( void )
  46. {
  47.    InitializeToolbox();
  48.  
  49.    gQuickDrawGXPresent = IsQuickDrawGXAvailable();
  50.    if ( gQuickDrawGXPresent == true )
  51.       InitializeQuickDrawGX();
  52.    else
  53.       ExitToShell();
  54.  
  55.    OpenDisplayWindow();
  56.  
  57.    while ( gDone == false )
  58.    {
  59.       if ( Button() )
  60.          CleanUpQuickDrawGXandQuit();
  61.    }      
  62. }
  63.  
  64.  
  65. //____________________________________________________________
  66.  
  67. Boolean  IsQuickDrawGXAvailable( void )
  68. {
  69.    OSErr  theError;
  70.    long   theResult;
  71.    
  72.    theError = Gestalt( gestaltGraphicsVersion, &theResult );
  73.    if ( theError != noErr )
  74.       return ( false );
  75.  
  76.    theError = Gestalt( gestaltGXPrintingMgrVersion, &theResult );
  77.    if ( theError != noErr )
  78.       return ( false );
  79.       
  80.    return ( true );
  81. }
  82.  
  83.  
  84. //____________________________________________________________
  85.  
  86. void  InitializeQuickDrawGX( void )
  87. {
  88.    gxGraphicsError  theGXgraphicsError;
  89.    OSErr            theGXprintError;      
  90.    
  91.    gGXClient = GXNewGraphicsClient( nil, kGXClientHeapSizeBytes, 0L );
  92.  
  93.    GXEnterGraphics();
  94.    theGXgraphicsError = GXGetGraphicsError( nil );
  95.    if ( theGXgraphicsError == out_of_memory )
  96.       ExitToShell();
  97.  
  98.    theGXprintError = GXInitPrinting();
  99.    if ( theGXprintError != noErr )
  100.       ExitToShell();
  101. }
  102.  
  103.  
  104. //____________________________________________________________
  105.  
  106. void  OpenDisplayWindow( void )
  107. {
  108.    gDisplayWindow = GetNewCWindow( 128, nil, (WindowPtr)-1L ); 
  109.    ShowWindow( gDisplayWindow );
  110.    SetPort( gDisplayWindow );
  111.    
  112.    gWindowViewPort = GXNewWindowViewPort( gDisplayWindow );
  113.  
  114.    CreateGXLineShape();
  115.  
  116.    GXSetShapeViewPorts( gLineShape, 1, &gWindowViewPort );
  117.  
  118.    GXDrawShape( gLineShape );  
  119. }
  120.  
  121.  
  122. //____________________________________________________________
  123.  
  124. void  CreateGXLineShape( void )
  125. {
  126.    gxLine  theLineGeometry = { {ff(50), ff(100)}, {ff(300), ff(60)} };
  127.    
  128.    gLineShape = GXNewShape( gxLineType );
  129.    GXSetLine( gLineShape, &theLineGeometry );
  130. }
  131.  
  132.  
  133. //____________________________________________________________
  134.  
  135. void  CleanUpQuickDrawGXandQuit( void )
  136. {
  137.    OSErr  theGXprintError;      
  138.  
  139.    if ( gDisplayWindow != nil )
  140.    {
  141.       GXDisposeViewPort( gWindowViewPort );
  142.       DisposeWindow( gDisplayWindow );  
  143.    }
  144.    
  145.    theGXprintError = GXExitPrinting();
  146.  
  147.    GXExitGraphics();
  148.    
  149.    GXDisposeGraphicsClient( gGXClient ); 
  150.  
  151.    gDone = true;
  152. }
  153.  
  154.  
  155. //____________________________________________________________
  156.  
  157. void  InitializeToolbox( void )
  158. {
  159.    InitGraf( &qd.thePort );
  160.    InitFonts();
  161.    InitWindows();
  162.    InitMenus();
  163.    TEInit();
  164.    InitDialogs( 0L );
  165.    FlushEvents( everyEvent, 0 );
  166.    InitCursor();
  167. }
  168.